<?php
class tran_companias extends Controller 
{
	public function __construct() 
	{
			parent::Controller();
			$this->load->model('mcompania');
			$this->load->helper(array('form','url'));
			$this->load->library(array('upload','form_validation'));
			$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
	}
	
	function data()
	{
		$page = $this->input->post('page') ? $this->input->post('page') : 1;
		$sortname = $this->input->post('sidx') ? $this->input->post('sidx') : 'ID_airport';
		$sortorder = $this->input->post('sord') ? $this->input->post('sord') : 'asc';
		$limit = $this->input->post('rows') ? $this->input->post('rows') : 10;
		
		$start = $limit * $page - $limit;
			if($start < 0) $start = 0;

			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
			header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
			header("Cache-Control: no-cache, must-revalidate" );
			header("Pragma: no-cache" );
			$records = $this->mcompania->LoadCompanias($this->input->post('nombre'), 
			$this->input->post('tipo'),$this->input->post('jurisdiccion'),
			$start, $limit, $sortname, $sortorder);

			$totalRecords = $this->mcompania->GetCount($this->input->post('nombre'), 
			$this->input->post('tipo'),$this->input->post('jurisdiccion'));

			$totalPages = ceil($totalRecords/$limit);
			if ($page > $totalPages) $page = $totalPages;

			$json_output = array(
				'page'		=> $page,
				'total'		=> $totalPages,
				'records'	=> $totalRecords,
				'rows'		=> array()
			);
			$compania=new compania();
			if($records != false) 
			{
				foreach($records as $compania) 
				{
					$servicio='Express';
					$jurisdiccion='Local';
					$etapa='Onapi';
					$arr = $json_output['rows'][] = array
					(
					'NombreCompania' =>$compania->getNombreCompania(), 
					'IdServicio' => $servicio,
					'IdJurisdiccion'=>$jurisdiccion,
					'FechaUsrCompania'=>$compania->getFechaUsrCompania(),
					'IdEtapa'=>$etapa,
					'IdStatus'=>$status,
					'imgetapa'=>$imgetapa,
					'imgtotal'=>$imgtotal,
					'IdUsuario'=>$usuario,
					'IdResponsable'=>$responsable
					);
				}
			}

			echo json_encode($json_output);
	}
}
?>